<?php
/**
 * @Name: NodeController.php
 * @Author: yashuai<1762910894@qq.com>
 */

namespace App\Http\Controllers\Admin\Rbac;

use Illuminate\Http\Request;
use App\Http\Logic\Rbac\NodeLogic;
use App\Http\Search\Rbac\NodeSearch;
use App\Http\Requests\StatusRequest;
use App\Http\Requests\Rbac\NodeSaveRequest;

class NodeController
{

    /**
     * 列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * @author yashuai<1762910894@qq.com>
     */
    public function index(Request $request)
    {
        $result = NodeSearch::instance($request->all())->index();
        return _success($result);
    }

    /**
     * 添加
     * @param NodeSaveRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ThrowException
     * @author yashuai<1762910894@qq.com>
     */
    public function create(NodeSaveRequest $request)
    {
        $result = NodeLogic::instance($request->getValidationData())->create();
        return _success($result);
    }

    /**
     * 编辑
     * @param NodeSaveRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ThrowException
     * @author yashuai<1762910894@qq.com>
     */
    public function update(NodeSaveRequest $request)
    {
        $validator = [
            'NodeID' => 'required|integer'
        ];
        $result    = NodeLogic::instance($request->getValidationData($validator))->update();
        return _success($result);
    }

    /**
     * @Desc 修改状态
     * @param StatusRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @throws \App\Exceptions\ThrowException
     * @author yashuai<1762910894@qq.com>
     */
    public function status(StatusRequest $request)
    {
        $result = NodeLogic::instance($request->getValidationData())->status();
        return _success($result);
    }

}
